<template>
    <section>
        <!--工具条-->
        <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
            <el-form :inline="true" :model="filters">


                <el-form-item label="运营商" prop="operatoruid">
                    <el-select v-model="filters.operatoruid" clearable filterable collapse-tags placeholder="请选择运营商">
                        <el-option value="0" label="全部">全部</el-option>
                        <el-option
                                v-for="item in operator"
                                :key="item.operatoruid"
                                :label="item.operatorname"
                                :value="item.operatoruid">
                        </el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="省份" prop="provinceuuid">
                    <el-select v-model="filters.provinceuuid" clearable filterable  collapse-tags :filter-method="selectfilter" placeholder="请选择省份">
                        <el-option value="0" label="全部">全部</el-option>
                        <el-option
                                v-for="item in info"
                                :key="item.provinceuuid"
                                :label="item.provincename"
                                :value="item.provinceuuid">
                            <span style="float: left">{{ item.provincename }}</span>
                            <span style="float: right; color: #8492a6; font-size: 13px">{{ item.label }}</span>
                        </el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="业务类型" prop="busuuid">
                    <el-select v-model="filters.busuuid" filterable clearable placeholder="请选择业务类型">
                        <el-option value="0" label="全部">全部</el-option>
                        <el-option
                                v-for="item in bus"
                                :key="item.busuuid"
                                :label="item.busname"
                                :value="item.busuuid">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="分销商" prop="useruuid">
                    <el-select v-model="filters.useruuid" clearable placeholder="请选择分销商" filterable v-show="isShow"
                               @change="userChange">
                        <el-option value="0" label="全部">全部</el-option>
                        <el-option
                                v-for="item in users"
                                :key="item.user.useruuid"
                                :label="item.user.username"
                                :value="item.user.useruuid">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="有效期" prop="validity">
                    <el-select v-model="filters.validity" filterable clearable placeholder="请选择运有效期">
                        <el-option value="0" label="全部">全部</el-option>
                        <el-option value="1" label="30天">30天</el-option>
                        <el-option value="2" label="当月">当月</el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-input v-model="filters.downfacevalue" clearable placeholder="面值"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" v-on:click="downProductFind">查询</el-button>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="exportDownProduct">导出</el-button>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" v-show="isShow" @click="handleAdd">新增</el-button>
                </el-form-item>
            </el-form>
        </el-col>

        <!--列表-->
        <el-table :data="products" highlight-current-row v-loading="listLoading" show-overflow-tooltip="true" max-height="620" border style="width: 100%;">
            <el-table-column type="index" width="65" label="编号">
            </el-table-column>
            <el-table-column prop="operators.operatorname" width="100px"  label="运营商">
            </el-table-column>
            <el-table-column prop="provincialInformation.provincename" label="省份">
            </el-table-column>
            <el-table-column prop="businessType.busname"  width="110px"  label="业务类型" show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="auto" label="匹配策略"   width="120px" :formatter="productAuto">
            </el-table-column>
            <el-table-column prop="user.username"  width="130px"  label="分销商" show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="downprouuid" width="200px" label="产品ID" show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="price"  width="110px" label="原价">
            </el-table-column>
            <el-table-column prop="downfacevalue"  width="100px" label="面值" :formatter="productType">
            </el-table-column>
            <el-table-column prop="productName" label="产品名称" width="130px" show-overflow-tooltip>
            </el-table-column>
<!--            <el-table-column prop="productCode" label="虚拟编码" width="100px">-->
<!--            </el-table-column>-->
            <el-table-column prop="discount"  width="100px" label="实际折扣">
            </el-table-column>
            <el-table-column prop="discountAmount"  width="110px" label="实际金额">
            </el-table-column>
            <el-table-column prop="validity" label="有效期":formatter="fastchargevalidity" >
            </el-table-column>
            <el-table-column prop="status" label="状态" width="100px" :formatter="status">
            </el-table-column>

            <el-table-column prop="remark" label="备注" >
            </el-table-column>
            <el-table-column label="操作" v-show="isShow"  fixed="right" width="250">
                <template scope="scope" v-show="isShow">
                    <el-button size="small" v-show="isShow" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                    <el-button size="small" v-show="isShow" @click="matchStrategy(scope.$index, scope.row)">匹配策略
                    </el-button>
                    <el-button size="small" v-show="isShow" @click="handleEnable(scope.$index, scope.row)">
                        {{scope.row.status == 2 ? '产品启用' : '产品维护'}}
                    </el-button>
                </template>
            </el-table-column>
        </el-table>

        <!--工具条-->
        <el-pagination
                @current-change="handleCurrentChange"
                @size-change="handleSizeChange"
                layout="total,sizes,prev, pager, next"
                :total="total">
        </el-pagination>
        <!--编辑界面-->
        <el-dialog title="编辑分销商产品" v-model="editFormVisible" :close-on-click-modal="false">
            <el-form :model="editForm" label-width="100px" :inline="true"  :rules="editFormRules" ref="editForm">
                <el-form-item label="运营商" prop="operatoruid">
                    <el-select v-model="editForm.operatoruid" filterable placeholder="请选择运营商">
                        <el-option
                                v-for="item in operator"
                                :key="item.operatoruid"
                                :label="item.operatorname"
                                :value="item.operatoruid">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="省份" prop="provinceuuid">
                    <el-select v-model="editForm.provinceuuid" filterable placeholder="请选择省份">
                        <el-option
                                v-for="item in info"
                                :key="item.provinceuuid"
                                :label="item.provincename"
                                :value="item.provinceuuid">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="业务类型" prop="busuuid">
                    <el-select v-model="editForm.busuuid" filterable placeholder="请选择业务类型">
                        <el-option
                                v-for="item in bus"
                                :key="item.busuuid"
                                :label="item.busname"
                                :value="item.busuuid">
                        </el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="分销商" prop="useruuid">
                    <el-select v-model="editForm.useruuid" filterable placeholder="请选择分销商">
                        <el-option
                                v-for="item in users"
                                :key="item.user.useruuid"
                                :label="item.user.username"
                                :value="item.user.useruuid">
                        </el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="产品名称" prop="productName"  >
                    <el-input v-model="editForm.productName"></el-input>
                </el-form-item>
<!--                <el-form-item label="虚拟编码" prop="productCode"  >-->
<!--                    <el-input v-model="editForm.productCode"></el-input>-->
<!--                </el-form-item>-->
                <el-form-item label="原价" prop="price">
                    <el-input v-model="editForm.price"  v-on:input="discountChangeEdit"></el-input>
                </el-form-item>
                <el-form-item label="面值" prop="downfacevalue">
                    <el-input v-model="editForm.downfacevalue"></el-input>
                </el-form-item>
                <el-form-item label="折扣" prop="discount">
                    <el-input v-model="editForm.discount"  v-on:input="discountChangeEdit"></el-input>
                </el-form-item>
                <el-form-item label="折扣后的成本金额" prop="discount">
                    <el-input v-model="editForm.discountAmount" :disabled="true"></el-input>
                </el-form-item>
                <!--<el-form-item label="快慢充类型"  prop="fastchargetype">-->
                <!--<el-radio-group v-model="editForm.fastchargetype">-->
                <!--<el-radio label="1" >快充</el-radio>-->
                <!--<el-radio label="0">慢充</el-radio>-->
                <!--</el-radio-group>-->
                <!--</el-form-item>-->
                <el-form-item label="有效期" prop="validity">
                    <el-select v-model="editForm.validity" filterable placeholder="请选择有效期">
                        <el-option value="0" label="全部">全部</el-option>
                        <el-option value="1" label="30天">30天</el-option>
                        <el-option value="2" label="当月">当月</el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="备注">
                    <el-input type="textarea" v-model="editForm.remark"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click.native="editFormVisible = false">取消</el-button>
                <el-button type="primary" @click.native="editSubmit" :loading="editLoading">提交</el-button>
            </div>
        </el-dialog>

        <!--新增界面-->
        <el-dialog title="新增分销商产品" size="small" v-model="addFormVisible" :close-on-click-modal="false">
            <el-form :model="addForm" label-width="100px" :inline="true"  :rules="addFormRules" ref="addForm">
                <el-form-item label="运营商" prop="operatoruid">
                    <el-select v-model="addForm.operatoruid" filterable placeholder="请选择运营商">
                        <el-option
                                v-for="item in operator"
                                :key="item.operatoruid"
                                :label="item.operatorname"
                                :value="item.operatoruid">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="省份" prop="provinceuuid">
                    <el-select v-model="addForm.provinceuuid" filterable placeholder="请选择省份">
                        <el-option
                                v-for="item in info"
                                :key="item.provinceuuid"
                                :label="item.provincename"
                                :value="item.provinceuuid">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="业务类型" prop="busuuid">
                    <el-select v-model="addForm.busuuid" filterable placeholder="请选择业务类型">
                        <el-option
                                v-for="item in bus"
                                :key="item.busuuid"
                                :label="item.busname"
                                :value="item.busuuid">
                        </el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="分销商" prop="useruuid">
                    <el-select v-model="addForm.useruuid" filterable placeholder="请选分销商">
                        <el-option
                                v-for="item in users"
                                :key="item.user.useruuid"
                                :label="item.user.username"
                                :value="item.user.useruuid">
                        </el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="产品名称" prop="productName"  >
                    <el-input v-model="addForm.productName"></el-input>
                </el-form-item>
<!--                <el-form-item label="虚拟编码" prop="productCode"  >-->
<!--                    <el-input v-model="addForm.productCode"></el-input>-->
<!--                </el-form-item>-->
                <el-form-item label="原价" prop="price">
                    <el-input v-model="addForm.price" v-on:input="discountChangeAdd"></el-input>
                </el-form-item>
                <el-form-item label="面值" prop="downfacevalue">
                    <el-input v-model="addForm.downfacevalue"></el-input>
                </el-form-item>
                <el-form-item label="折扣" prop="discount">
                    <el-input v-model="addForm.discount"  v-on:input="discountChangeAdd"></el-input>
                </el-form-item>
                <el-form-item label="折扣后的成本金额" prop="discount">
                    <el-input v-model="addForm.discountAmount" :disabled="true" ></el-input>
                </el-form-item>
                <el-form-item label="有效期" prop="validity">
                    <el-select v-model="addForm.validity" filterable placeholder="请选择有效期">
                        <el-option value="0" label="全部">全部</el-option>
                        <el-option value="1" label="30天">30天</el-option>
                        <el-option value="2" label="当月">当月</el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="备注">
                    <el-input type="textarea" v-model="addForm.remark"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click.native="addFormVisible = false">取消</el-button>
                <el-button type="primary" @click.native="addUpProduct" :loading="addLoading">提交</el-button>
            </div>
        </el-dialog>

        <el-dialog title="产品匹配策略" size="big" v-model="matchVisible" :close-on-click-modal="false">
            <el-form :model="matchForm" :inline="true" label-width="100px" :rules="matchRules" ref="matchForm">
                <el-form-item label="运营商" prop="operatoruid">
                    <el-select v-model="matchForm.operatoruid" filterable placeholder="请选择运营商">
                        <el-option value="0" label="全部">全部</el-option>
                        <el-option
                                v-for="item in operator"
                                :key="item.operatoruid"
                                :label="item.operatorname"
                                :value="item.operatoruid">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="省份" prop="provinceuuid">
                    <el-select v-model="matchForm.provinceuuid" filterable placeholder="请选择省份">
                        <el-option value="0" label="全部">全部</el-option>
                        <el-option
                                v-for="item in info"
                                :key="item.provinceuuid"
                                :label="item.provincename"
                                :value="item.provinceuuid">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="业务类型" prop="busuuid">
                    <el-select v-model="matchForm.busuuid" filterable placeholder="请选择业务类型">
                        <el-option value="0" label="全部">全部</el-option>
                        <el-option
                                v-for="item in bus"
                                :key="item.busuuid"
                                :label="item.busname"
                                :value="item.busuuid">
                        </el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="供货商" prop="useruuid">
                    <el-select v-model="matchForm.useruuid" multiple placeholder="请选择供货商">
                        <el-option
                                v-for="item in usersUp"
                                :key="item.user.useruuid"
                                :label="item.user.username"
                                :value="item.user.useruuid">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" v-on:click="downProductMatchFind">查询</el-button>
                </el-form-item>
                <!--列表-->
                <el-table :data="upproducts" highlight-current-row v-loading="listLoading" border  max-height="620" ref="multipleTable" show-overflow-tooltip="true"
                          @selection-change="handleSelectionChange" style="width: 100%;">
                    <el-table-column type="selection" width="55"  >
                    </el-table-column>
                    <el-table-column prop="operators.operatorname" label="运营商">
                    </el-table-column>
                    <el-table-column prop="provincialInformation.provincename" label="省份">
                    </el-table-column>
                    <el-table-column prop="businessType.busname" label="业务类型">
                    </el-table-column>
                    <el-table-column prop="user.username" label="供货商">
                    </el-table-column>
                    <el-table-column prop="productCode" label="产品编码">
                    </el-table-column>
                    <el-table-column prop="productName" label="产品名称">
                    </el-table-column>
                    <el-table-column prop="price" label="原价">
                    </el-table-column>
                    <el-table-column prop="upfacevalue" label="面值" :formatter="productUp">
                    </el-table-column>
                    <el-table-column prop="discount" label="折扣">
                    </el-table-column>
                    <el-table-column prop="discountAmount" label="折扣后的成本金额">
                    </el-table-column>
                    <!--<el-table-column prop="fastchargetype" label="快慢类型":formatter="fastchargetype" >-->
                    <!--</el-table-column>-->
                    <el-table-column prop="status" label="状态" :formatter="status">
                    </el-table-column>
                </el-table>

                <!--工具条-->
                <el-pagination
                        @current-change="handleCurrentChangeMatch"
                        @size-change="handleSizeChangeMatch"
                        layout="total,sizes,prev, pager, next"
                        :total="totalMatch">
                </el-pagination>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click.native="matchVisible = false">取消</el-button>
                <el-button type="primary" @click.native="saveMatch" :loading="matchFormLoading">保存策略</el-button>
            </div>
        </el-dialog>
    </section>
</template>

<script>
    import util from '../../common/js/util'
    var pinyin = require("pinyin");
    //import NProgress from 'nprogress'
    import {
        downProductFind,
        exportDownProduct,
        findByDownProvince,
        findOpeProBusShop,
        addDownProduct,
        findOneDownProduct,
        updateDownProduct,
        productDownEnable,
        findAllBus,
        findAllDownShopInfo,
        downProductMatchFind,
        findAllUpShopInfo,
        addProductStrategy,
        downfindlist,
        findByProductFetchInclu,
        autoProduct
    } from '../../api/api';

    export default {
        data() {
            return {
                filters: {
                    name: '',
                    downorderuuid:'',
                    provinceuuid:'',
                    busuuid: '',
                    useruuid: '',
                    operatoruid:'',
                    validity:'',
                    downfacevalue: '',
                    isShow: JSON.parse(sessionStorage.getItem("user")).usertype == 1 ? true : JSON.parse(sessionStorage.getItem("user")).usertype == 2 ? true : false
                },
                isShow: JSON.parse(sessionStorage.getItem("user")).usertype == 1 ? true : JSON.parse(sessionStorage.getItem("user")).usertype == 2 ? true :  false,
                products: [],
                total: 0,
                start: 0,
                pageSize: 10,
                totalMatch: 0,
                startMatch: 0,
                pageSizeMatch: 10,
                listLoading: false,
                matchForm: {
                    productCode: '',
                    operatoruid: '',
                    provinceuuid: '',
                    busuuid: '',
                    useruuid: '',
                },
                matchFormLoading: false,
                matchVisible: false,
                matchRules: {},


                editFormVisible: false,//编辑界面是否显示
                editLoading: false,
                editFormRules: {
                    operatoruid: [
                        {required: true, message: '请选择运营商', trigger: 'blur'}
                    ],
                    provinceuuid: [
                        {required: true, message: '请选择省份', trigger: 'blur'}
                    ],
                    busuuid: [
                        {required: true, message: '请选择业务类型', trigger: 'blur'}
                    ],
                    useruuid: [
                        {required: true, message: '请选择渠道商', trigger: 'blur'}
                    ],
                    downfacevalue: [
                        {required: true, message: '请输入面值', trigger: 'blur'}
                    ],
                    productCode: [
                        {required: true, message: '请输入虚拟编码', trigger: 'blur'}
                    ],
                    productName:[
                        {required: true, message: '请输入产品名称', trigger: 'blur'}
                    ],
                    discount: [
                        {required: true, message: '请输入折扣', trigger: 'blur'},
                        {min: 1, max: 8, message: '长度在 1 到 3 个字符', trigger: 'blur'},
                    ],
                    fastchargetype: [
                        {required: true, message: '请选择快慢充类型', trigger: 'blur'}
                    ],price:[
                        {required: true, message: '请输入原价', trigger: 'blur'}
                    ],validity:[
                        {required: true, message: '请选择有效期', trigger: 'blur'}
                    ],productName: [
                        {required: true, message: '请输入产品名称', trigger: 'blur'}
                    ],
                },
                //编辑界面数据
                editForm: {
                    operatoruid: '',
                    provinceuuid: '',
                    busuuid: '',
                    validity:'',
                    productName:'',
                    user: {useruuid: ''},
                    productCode: '',
                    downfacevalue: '',
                    discount: '1',
                    fastchargetype: '1',
                    remark: '',
                    useruuid: '',
                    downfailnum: 1,
                    downtimeinterva: 1,
                    downprouuid: '',
                    price:"0",
                    discountAmount:''
                },

                addFormVisible: false,//新增界面是否显示
                addLoading: false,
                addFormRules: {
                    operatoruid: [
                        {required: true, message: '请选择运营商', trigger: 'blur'}
                    ],
                    provinceuuid: [
                        {required: true, message: '请选择省份', trigger: 'blur'}
                    ],
                    busuuid: [
                        {required: true, message: '请选择业务类型', trigger: 'blur'}
                    ],
                    useruuid: [
                        {required: true, message: '请选择渠道商', trigger: 'blur'}
                    ],
                    downfacevalue: [
                        {required: true, message: '请输入面值,如果是话费则是对应的充值原价,如果是流量则是xxM', trigger: 'blur'}
                    ],
                    productName: [
                        {required: true, message: '请输入产品名称', trigger: 'blur'}
                    ],
                    discount: [
                        {required: true, message: '请输入折扣', trigger: 'blur'},
                        {min: 1, max: 8, message: '长度在 1 到 3 个字符', trigger: 'blur'},
                    ],
                    fastchargetype: [
                        {required: true, message: '请选择快慢充类型', trigger: 'blur'}
                    ],
                    price:[
                        {required: true, message: '请输入原价', trigger: 'blur'}
                    ],validity:[
                        {required: true, message: '请选择有效期', trigger: 'blur'}
                    ],  productCode: [
                        {required: true, message: '请输入虚拟编码', trigger: 'blur'}
                    ],
                },
                //新增界面数据
                addForm: {
                    operatoruid: '',
                    provinceuuid: '',
                    busuuid: '',
                    user: {useruuid: ''},
                    productCode: '',
                    downfacevalue: '',
                    discount: '1',
                    fastchargetype: '1',
                    remark: '',
                    productName:'',
                    useruuid: '',
                    downfailnum: 1,
                    downtimeinterva: 1,
                    validity:'',
                    price:'0',
                    discountAmount:''
                },
                //下拉数据
                operator: [],
                info: [],
                bus: [],
                users: [],
                usersUp:[],
                upproducts: [],
                sels: [],
                matchProduct: {},
                ups:[]
            }
        },
        methods: {
            fastchargevalidity:function(row, column){
                return (row.validity === "1") ? "30天" : (row.validity === "2") ?  "当月" : "未知";
            },
            productAuto: function (row, column) {
                return (row.auto === 1) ? "手动匹配" : (row.auto === 0) ?  "自动匹配" : "未知";
            },
            productUp: function (row, column) {
                return (row.businessType.busname == "手机") ? (row.upfacevalue + '话费') : ( row.businessType.busname == "固话") ?  (row.upfacevalue + '话费') :(row.upfacevalue + 'M');
            },
            productType: function (row, column) {
                return (row.businessType.busname == "手机") ? (row.downfacevalue + '话费') : ( row.businessType.busname == "固话") ?  (row.downfacevalue + '话费') :(row.downfacevalue + 'M');
            },
            fastchargetype: function (row, column) {
                return row.fastchargetype == 1 ? '快充' : row.fastchargetype == 0 ? '慢充' : '未知';
            },
            status: function (row, column) {
                return row.status == "1" ? '产品正常' : row.status == "0" ? '删除' : row.status == "2" ? "产品维护" : '未知';
            },
            selectfilter:function(row){
                if(row != ""){
                    for(let str in this.info){
                        if(this.info[str].label == row){
                            this.filters.provinceuuid = this.info[str].provinceuuid;
                        }
                    }
                }
            }, handleSelectionChange: function (sels) {
                this.sels = sels;
            }, downProductMatchFind: function () {
                let para = {
                    start: this.startMatch,
                    pageSize: this.pageSizeMatch,
                    busuuid: this.matchForm.busuuid == "0" ? "" : this.matchForm.busuuid,
                    operatoruid: this.matchForm.operatoruid == "0" ? "" : this.matchForm.operatoruid,
                    provinceuuid: this.matchForm.provinceuuid == "0" ? "" : this.matchForm.provinceuuid,
                    useruuids: this.matchForm.useruuid == "0" ? "" : this.matchForm.useruuid
                };
                this.listLoading = false;
                this.findAllUpShopInfo();
                downProductMatchFind(para).then((datas) => {
                    let {message, code, data} = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        this.upproducts = data.result;
                        this.totalMatch = data.totalCount;
                        for(var i  = 0 ; i < this.upproducts.length; i++){
                            let para = {
                                uporderuuid:this.upproducts[i].upprouuid,
                                downprouuid:this.matchProduct.downprouuid
                            };
                            findByProductFetchInclu(para).then(datas =>{
                                let {message, code, data} = datas;
                                if(data != ""){
                                    for(var j  = 0 ; j < this.upproducts.length; j++) {
                                        if (this.upproducts[j].upprouuid == data) {
                                            this.$refs.multipleTable.toggleRowSelection(this.upproducts[j], true);
                                        }
                                    }
                                }
                            });
                        }
                    }
                    this.listLoading = false;
                });
            },
            handleCurrentChangeMatch: function (val) {
                this.startMatch = val - 1;
                this.downProductMatchFind();
            },
            handleSizeChangeMatch: function (val) {
                this.pageSizeMatch = val;
                this.downProductMatchFind();
            },
            infochange: function (info) {

            }, handleEnable: function (index, row) {

                this.$confirm('确认更新该产品状态吗?', '提示', {
                    type: 'warning'
                }).then(() => {
                    this.listLoading = true;
                    let para = {
                        downprouuid: row.downprouuid,
                        status: row.status == "2" ? "1" : "2",
                        useruuid: JSON.parse(sessionStorage.getItem("user")).useruuid
                    };
                    productDownEnable(para).then((res) => {
                        this.listLoading = false;
                        //NProgress.done();
                        this.$message({
                            message: '操作成功',
                            type: 'success'
                        });
                        this.downProductFind();
                    });
                }).catch(() => {

                });
            }, findAllDownShopInfo: function () {
                let para = {useruuid: JSON.parse(sessionStorage.getItem("user")).useruuid};
                findAllDownShopInfo(para).then(datas => {
                    let {message, code, data} = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        this.users = data;
                    }
                });
            }, findAllUpShopInfo: function () {
                let para = {useruuid: ''};
                findAllUpShopInfo(para).then(datas => {
                    let {message, code, data} = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        this.usersUp = data;
                    }
                });
            },
            downfindlist:function(){
                downfindlist().then(datas =>{
                    let { message, code, data } = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        this.ups =   data;
                    }
                });
            },
            downProductFind() {
                let para = {
                    start: this.start,
                    pageSize: this.pageSize,
                    operatoruid: this.filters.operatoruid == "0" ? "": this.filters.operatoruid,
                    provinceuuid:  this.filters.provinceuuid == "0" ? "" : this.filters.provinceuuid,
                    busuuid: this.filters.busuuid == "0" ? "" : this.filters.busuuid,
//                  useruuid:JSON.parse(sessionStorage.getItem("user")).useruuid ,
                    downfacevalue: this.filters.downfacevalue,
                    useruuid: this.filters.useruuid == "0" ? "": this.filters.useruuid,
                    downprouuid: '',
                    fastchargetype: '',
                    validity:  this.filters.validity == "0" ? "": this.filters.validity
                };
                this.listLoading = true;
                downProductFind(para).then((datas) => {
                    let {message, code, data} = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        this.products = data.result;
                        this.total = data.totalCount;
                    }
                    this.listLoading = false;
                });
            },
            exportDownProduct(){
                let para = {
                    operatoruid:this.filters.operatoruid == "0" ? "" : this.filters.operatoruid,
                    provinceuuid: this.filters.provinceuuid == "0" ? "" : this.filters.provinceuuid ,
                    busuuid: this.filters.busuuid == "0" ? "" : this.filters.busuuid,
//                  useruuid:JSON.parse(sessionStorage.getItem("user")).useruuid ,
                    downfacevalue: this.filters.downfacevalue,
                    useruuid: this.filters.useruuid == "0" ? "": this.filters.useruuid,
                    downprouuid: '',
                    fastchargetype: ''
                };
                this.listLoading = true;
                exportDownProduct(para).then((datas) => {
                    let {message, code, data} = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        window.open(data.path);
                    }
                    this.listLoading = false;
                });
            },
            //删除
            handleDel: function (index, row) {
                this.$confirm('确认删除该记录吗?', '提示', {
                    type: 'warning'
                }).then(() => {
                    this.listLoading = true;
                    //NProgress.start();
                    let para = {id: row.id};
                    removeUser(para).then((res) => {
                        this.listLoading = false;
                        //NProgress.done();
                        this.$message({
                            message: '删除成功',
                            type: 'success'
                        });
                        this.downProductFind();
                    });
                }).catch(() => {

                });
            },
            //显示编辑界面
            handleEdit: function (index, row) {
                this.editFormVisible = true;
                this.downfindlist();
                let para = {
                    downprouuid: row.downprouuid
                };
                findOpeProBusShop(para).then(datas => {
                    let {message, code, data} = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        this.operator = data.operator;
                        this.info = data.info;
                        this.bus = data.bus;
                        findOneDownProduct(para).then(datas => {
                            let {message, code, data} = datas;
                            if (code !== "0") {
                                this.$message({
                                    message: message,
                                    type: 'error'
                                });
                            } else {
                                this.editForm.operatoruid = data.operators.operatoruid;
                                this.editForm.provinceuuid = data.provincialInformation.provinceuuid;
                                this.editForm.busuuid = data.businessType.busuuid;
                                this.editForm.useruuid = data.user.useruuid;
                                this.editForm.fastchargetype = data.fastchargetype + "";
                                this.editForm.productCode = data.productCode;
                                this.editForm.downfacevalue = data.downfacevalue;
                                this.editForm.discount = data.discount;
                                this.editForm.remark = data.remark;
                                this.editForm.downprouuid = data.downprouuid;
                                this.editForm.price = data.price;
                                this.editForm.discountAmount = data.discountAmount;
                                this.editForm.productName = data.productName;
                                this.editForm.validity = data.validity;
                            }
                        });
                    }
                });
            }, findAllBus: function () {
                let para = {useruuid: ''};
                findAllBus(para).then(datas => {
                    let {message, code, data} = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        this.bus = data;
                    }
                });
            },
            //显示新增界面
            handleAdd: function () {
                this.addFormVisible = true;
                let para = {
                    test: ''
                };
                this.downfindlist();
                findOpeProBusShop(para).then(datas => {
                    let {message, code, data} = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        this.operator = data.operator;
                        this.info = data.info;
                        this.bus = data.bus;
//                        this.users = data.users;
                    }
                });
                this.findAllDownShopInfo();

            },
            //编辑
            editSubmit: function () {
                this.$refs.editForm.validate((valid) => {
                    if (valid) {
                        this.$confirm('确认提交吗？', '提示', {}).then(() => {
                            this.editLoading = true;
                            let para = Object.assign({}, this.editForm);
                            updateDownProduct(para).then((datas) => {
                                this.editLoading = false;
                                let {message, code, data} = datas;
                                if (code !== "0") {
                                    this.$message({
                                        message: message,
                                        type: 'error'
                                    });
                                }
                                this.$refs['editForm'].resetFields();
                                this.editFormVisible = false;
                                this.downProductFind();
                            });
                        });
                    }
                });
            },
            //新增
            addUpProduct: function () {
                this.$refs.addForm.validate((valid) => {
                    if (valid) {
                        this.$confirm('确认提交吗？', '提示', {}).then(() => {
                            this.addLoading = true;
                            //NProgress.start();
                            let para = Object.assign({}, this.addForm);
                            addDownProduct(para).then((datas) => {
                                this.addLoading = false;
                                let {message, code, data} = datas;
                                if (code !== "0") {
                                    this.$message({
                                        message: message,
                                        type: 'error'
                                    });
                                }
//                                this.$refs['addForm'].resetFields();
//                                this.addFormVisible = false;
                                this.downProductFind();
                            });
                        });
                    }
                });
            },
            discountChangeAdd:function () {
                this.addForm.discountAmount = (this.addForm.discount * this.addForm.price).toFixed(5);
            },
            discountChangeEdit:function () {
                this.editForm.discountAmount = (this.editForm.discount * this.editForm.price).toFixed(5);
            },
            userChange: function (user) {
                this.addForm.useruuid = user;
            },
            handleCurrentChange: function (val) {
                this.start = val - 1;
                this.downProductFind();
            },
            handleSizeChange: function (val) {
                this.pageSize = val;
                this.downProductFind();
            },
            matchStrategy: function (index, row) {
                this.matchProduct = row;
                this.matchVisible = true;
                let para = {sdffds: ''};
                findOpeProBusShop(para).then(datas => {
                    let {message, code, data} = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        this.operator = data.operator;
                        this.info = data.info;
                        this.bus = data.bus;

                        this.downProductMatchFind();
                    }
                });
            },
            findOpeProBusShop(){
                let para = {sdffds: ''};
                findOpeProBusShop(para).then(datas => {
                    let {message, code, data} = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        this.operator = data.operator;
                        this.info = data.info;
                        for(let obj in this.info){
                            this.info[obj].label= this.getPingYing(this.info[obj].provincename);
                        }
//                        this.bus = data.bus;
                    }
                });
            },getPingYing(content){
                const result = pinyin(content, {
                    style: pinyin.STYLE_FIRST_LETTER, // 设置拼音风格
//                    heteronym: true
                });
                var temp = "";
                for(let res in result){
                    temp += result[res];
                }
                return temp;
            },
            saveMatch: function () {
                let para = {
                    downprouuid: this.matchProduct.downprouuid,
                    upprouuids:this.sels,
                    remark:'add match'
                };
                addProductStrategy(para).then(datas => {
                    let {message, code, data} = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        this.matchVisible = false;
                    }
                });
            },toggleSelection(rows) {
                if (rows) {
                    rows.forEach(row => {
                        this.$refs.multipleTable.toggleRowSelection(row,true);
                    });
                } else {
                    this.$refs.multipleTable.clearSelection();
                }
            }
            /////////////////////////////产品名称///////////////////////////////
        },
        mounted() {
            this.findOpeProBusShop();
            this.findAllBus();
            this.findAllDownShopInfo();
            this.downProductFind();
        }
    }

</script>

<style scoped>

</style>
